package com.tomvian.tools 
{
	import flash.display.Shape;
	import flash.events.Event;
	import flash.utils.getTimer;
	import org.osflash.signals.Signal;
	/**
	 * OmniTick
	 * @author Tom Vian
	 */
	public class OmniTick
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public static const tick:OmniTick = new OmniTick;
		
		private var _shape:Shape;
		
		public var onTick:Signal;
		
		public var tickTime:uint;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function OmniTick() 
		{
			_shape = new Shape;
			onTick = new Signal;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function start():void
		{
			_shape.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		public function stop():void
		{
			_shape.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(e:Event):void 
		{
			var t:uint = getTimer();
			onTick.dispatch();
			tickTime = getTimer() - t;
		}
	}
}